package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.TtsWarn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.ITtsWarnService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 预警Controller
 * 
 * @author li
 * @date 2025-08-18
 */
@Api(tags = "天童寺设备预警数据")
@RestController
@RequestMapping("/system/warn")
public class TtsWarnController extends BaseController
{
    @Autowired
    private ITtsWarnService ttsWarnService;

    /**
     * 查询预警列表
     */
    @ApiOperation("天童寺告警列表")
    @GetMapping("/list")
    public AjaxResult list(TtsWarn ttsWarn)
    {
        List<TtsWarn> list = ttsWarnService.selectTtsWarnList(ttsWarn);
        return success(list);
    }

    /**
     * 导出预警列表
     */
    @Log(title = "预警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TtsWarn ttsWarn)
    {
        List<TtsWarn> list = ttsWarnService.selectTtsWarnList(ttsWarn);
        ExcelUtil<TtsWarn> util = new ExcelUtil<TtsWarn>(TtsWarn.class);
        util.exportExcel(response, list, "预警数据");
    }

    /**
     * 获取预警详细信息
     */
    @ApiOperation("获取预警详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ttsWarnService.selectTtsWarnById(id));
    }

    /**
     * 新增预警
     */
    @Log(title = "预警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TtsWarn ttsWarn)
    {
        return toAjax(ttsWarnService.insertTtsWarn(ttsWarn));
    }

    /**
     * 修改预警
     */
    @ApiOperation("修改预警详细信息")
    @Log(title = "预警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TtsWarn ttsWarn)
    {
        return toAjax(ttsWarnService.updateTtsWarn(ttsWarn));
    }

    /**
     * 删除预警
     */
    @Log(title = "预警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ttsWarnService.deleteTtsWarnByIds(ids));
    }

    /**
     * 获取首页预警统计数据
     */
    @GetMapping(value = "/getWarningStatis")
    public AjaxResult getWarningStatis()
    {
        return success(ttsWarnService.selectTtsWarningStatis());
    }

    /**
     * 获取安防页面报警统计数据
     */
    @GetMapping(value = "/getWarningAfStatis")
    public AjaxResult getWarningAfStatis()
    {
        return success(ttsWarnService.selectTtsWarningAfStatis());
    }
}